const ApiErrorNames = require('./ApiErrorNames');
/**
 * Error 继承踩坑记
 * 修正继承后Error this的指向问题
 */
class ExtensibleError {
}
function ExtendableErrorBuiltin(){
    function ExtendableBuiltin(){
        Error.apply(this, arguments);
        if (typeof Error.captureStackTrace === 'function') {
            // Set this.stack
            Error.captureStackTrace(this, this.constructor)
        }
    }
    ExtendableBuiltin.prototype = Object.create(Error.prototype);
    Object.setPrototypeOf(ExtendableBuiltin, Error);
    return ExtendableBuiltin;
}

ExtensibleError = ExtendableErrorBuiltin(Error)
/**
 * 自定义Api异常
 */
class ApiError extends ExtensibleError {
    //构造方法
    constructor(error_name){
        super();
        var error_info = ApiErrorNames.getErrorInfo(error_name);

        this.name = error_name;
        this.code = error_info.code;
        this.message = error_info.message;
    }
}

export default ApiError;
